feat(filters): add filter component that reloads the pokemon list #25
+661
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solves #12. Stacked on #24, so review that one first. The chain is this branch ->
fix/issue-6-build-errors->issue-6->main.Adds the filter view the issue asks for: the user changes the rules, and the PokemonList reloads from them. The rules go through
useFilters, so they are already kept in session storage and survive a reload.The component
Filteris presentational in the same shape asFavorite, takingfilters,onChangeandonReset. It sits in the header row next to the navigation.It is collapsed behind a
details/summarydisclosure, which keeps the header row from being crowded by eighteen type checkboxes and gives keyboard and screen reader support without a third party component. The summary shows how many rules are active so you can see at a glance that something is filtered while it is shut. Controls are grouped infieldset/legendwith alabelon every input.Three rules are exposed:
The stat range rules the model already supports (
hp,attack,heightand so on) are deliberately left out of the UI for now. They keep working through the model and can get controls later.Wiring the rules up
sortandonlyFavoriteswere in the model but were not read anywhere, so picking them would have done nothing. Both are applied now:The favorites view reuses the pokemon
useFavoriteshas already fetched rather than asking the api again, so switching it on costs no extra calls. The list query is disabled while it is on.Also removes
FilterSettings, which nothing referenced after the model moved toFilterRules.Tests
Fourteen new tests, none of them touching the network.
Filter.test.tsx, nine tests on props, on the toggle state, and on user interaction, plus a snapshotPokemonList.test.tsx, five tests, restoring the file that was removed in chore: glue components together #23. Covers the fetched order, the reversed order, the favorites view, the other rules applying to favorites, and the empty state. It also asserts that the favorites view calls neitherGetNextFilterednorGetPrevFiltered.setupTests.tsnow imports@testing-library/jest-dom/vitestinstead of the plain entry point. The matchers were already loaded at runtime, but their types were not, sotoBeCheckedandtoBeInTheDocumentfailed undertsc.Checks
tsc -b,eslint .,prettier --checkandvite buildare all clean.vitest runis 48 passed across 9 files, up from 34 across 7.